var createError = require('http-errors');
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var register = require('./routes/register');
var check = require('./routes/check');
var update = require('./routes/update');
var quit = require('./routes/quit');
var upload = require('./routes/upload');
var uploads = require('./routes/uploads');
var cover = require('./routes/cover');
var photo = require('./routes/photo');
var photoUrl = require('./routes/photoUrl');
var article = require('./routes/article');
var articlelist = require('./routes/article-list');
var personalArticleList= require('./routes/personal-article-list');
var personalInformation= require('./routes/personal-information');
var personalInformations= require('./routes/personal-informations');
var personal= require('./routes/personal');
var app = express();
app.set('jwtTokenSecret', 'YOUR_SECRET_STRING');
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.engine('.html', require('ejs').renderFile);
app.set('view engine', 'html');

 app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false })); 

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/register', register);
app.use('/check', check);
app.use('/update', update);
app.use('/quit', quit);
app.use('/upload', upload);
app.use('/uploads', uploads);
app.use('/cover',cover);
app.use('/photo',photo);
app.use('/photoUrl',photoUrl);
app.use('/article', article);
app.use('/article-list',articlelist)
app.use('/personal-article-list',personalArticleList)
app.use('/personal-information',personalInformation)
app.use('/personal-informations',personalInformations)
app.use('/personal',personal)
// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});



module.exports = app;
